package com.gomyb.utils;

import com.alibaba.fastjson.JSON;
import com.gomyb.result.R;
import com.gomyb.result.RCode;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 */
public class WriteUtils {

    public static void writeOK(HttpServletRequest request, HttpServletResponse response, String remark) {
        HttpUtils.setResponse(request, response);
        try (PrintWriter writer = response.getWriter()) {
            writer.write(JSON.toJSONString(R.OK(remark)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void writeNO(HttpServletRequest request, HttpServletResponse response, RCode resultCode) {
        HttpUtils.setResponse(request, response);
        try (PrintWriter writer = response.getWriter()) {
            writer.write(JSON.toJSONString(R.NO(resultCode)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
